package com.zzz.web.LocationAlgo;

import com.zzz.web.Data.RSSI;
import com.zzz.web.tools.tool;

public class UserWayPredict {
    RSSI[][] RSSIs;

    int oldx, oldy;

    public boolean predict(RSSI rssi) {
        RSSIs = tool.getCurrentRSSIs();

        for (int x = oldx - 1; x <= oldx + 1; x++) {
            for (int y = oldy - 1; y <= oldy + 1; y++) {
                if(tool.isClose(RSSIs[x][y],rssi)){
                    oldx = x;
                    oldy = y;
                    return true;
                }
            }
        }
        for (int x = oldx - 2; x <= oldx + 2; x += 1 ) {

            if(x == oldx -2 || x == oldx +2){
                for(int y = oldy -2;y<=oldy+2;y++){
                    if(tool.isClose(RSSIs[x][y],rssi)){
                        oldx = x;
                        oldy = y;
                        return true;
                    }
                }
            }
            else {
                for (int y = oldy -2;y<= oldy+2;y+=4){
                    if(tool.isClose(RSSIs[x][y],rssi)){
                        oldx = x;
                        oldy = y;
                        return true;
                    }
                }
            }
        }

        return false;
    }
}

